home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 076-100 / disk_077 / misc / view.d < prev    next >
Text File  |  1992-05-06  |  5KB  |  184 lines

  1. #include:graphics/gfx.g
  2. #include:graphics/view.g
  3. #include:graphics/gfxbase.g
  4. #include:graphics/copper.g
  5. #include:graphics/rastport.g
  6.  
  7. uint
  8.     SCREEN_HEIGHT = 200,
  9.  
  10.     GRAPHICS_DEPTH = 5,
  11.     GRAPHICS_COLORS = 1 << GRAPHICS_DEPTH,
  12.     GRAPHICS_WIDTH = 320,
  13.     GRAPHICS_HEIGHT = 128,
  14.  
  15.     TEXT_DEPTH = 1,
  16.     TEXT_COLORS = 1 << TEXT_DEPTH,
  17.     TEXT_WIDTH = 640,
  18.     TEXT_HEIGHT = SCREEN_HEIGHT;
  19.  
  20. View_t View;
  21. ViewPort_t GraphicsViewPort, TextViewPort;
  22. RasInfo_t GraphicsRasInfo, TextRasInfo;
  23. RastPort_t GraphicsRastPort, TextRastPort;
  24.  
  25. uint TextTopLine;
  26.  
  27. proc makeView()void:
  28.  
  29.     GraphicsRasInfo.ri_RyOffset := GRAPHICS_HEIGHT + 1 - TextTopLine;
  30.     GraphicsViewPort.vp_DHeight := TextTopLine - 1;
  31.     TextRasInfo.ri_RyOffset := TextTopLine;
  32.     TextViewPort.vp_DHeight := TEXT_HEIGHT - TextTopLine;
  33.     TextViewPort.vp_DyOffset := TextTopLine;
  34.     MakeVPort(&View, &TextViewPort);
  35.     MakeVPort(&View, &GraphicsViewPort);
  36.     MrgCop(&View);
  37.     WaitTOF();
  38.     LoadView(&View);
  39. corp;
  40.  
  41. proc doit()void:
  42.     uint i, j;
  43.     [GRAPHICS_COLORS]uint colorTable;
  44.  
  45.     SetAPen(&TextRastPort, 1);
  46.     for i from 7 by 8 upto 7 + 8 * (TEXT_HEIGHT / 8 - 2) do
  47.     Move(&TextRastPort, 0, i);
  48.     Text(&TextRastPort, "Hello there world!", 18);
  49.     od;
  50.  
  51.     for i from 0 upto GRAPHICS_COLORS - 1 do
  52.     SetAPen(&GraphicsRastPort, i);
  53.     RectFill(&GraphicsRastPort,
  54.         i * (GRAPHICS_WIDTH / GRAPHICS_COLORS / 2),
  55.         i * (GRAPHICS_HEIGHT / GRAPHICS_COLORS / 2),
  56.         GRAPHICS_WIDTH - 1 - i * (GRAPHICS_WIDTH / GRAPHICS_COLORS / 2),
  57.         GRAPHICS_HEIGHT - 1 - i * (GRAPHICS_HEIGHT / GRAPHICS_COLORS / 2));
  58.     od;
  59.  
  60.     for i from 1 upto GRAPHICS_HEIGHT - 10 do
  61.     TextTopLine := TextTopLine - 1;
  62.     makeView();
  63.     od;
  64.     for i from 1 upto GRAPHICS_HEIGHT - 10 do
  65.     TextTopLine := TextTopLine + 1;
  66.     makeView();
  67.     od;
  68. corp;
  69.  
  70. proc main()void:
  71.     BitMap_t graphicsBitMap, textBitMap;
  72.     *GfxBase_t gfxBase;
  73.     *View_t oldView;
  74.     uint i;
  75.     bool failing;
  76.  
  77.     gfxBase := OpenGraphicsLibrary(0);
  78.     if gfxBase ~= nil then
  79.     TextTopLine := GRAPHICS_HEIGHT + 1;
  80.     failing := false;
  81.     oldView := gfxBase*.gb_ActiView;
  82.  
  83.     InitView(&View);
  84.     View.v_ViewPort := &GraphicsViewPort;
  85.     
  86.     InitBitMap(&graphicsBitMap, GRAPHICS_DEPTH,
  87.             GRAPHICS_WIDTH, GRAPHICS_HEIGHT);
  88.     for i from 0 upto GRAPHICS_DEPTH - 1 do
  89.         graphicsBitMap.bm_Planes[i] :=
  90.         AllocRaster(GRAPHICS_WIDTH, GRAPHICS_HEIGHT);
  91.         if graphicsBitMap.bm_Planes[i] = nil then
  92.         failing := true;
  93.         fi;
  94.     od;
  95.     InitBitMap(&textBitMap, TEXT_DEPTH, TEXT_WIDTH, TEXT_HEIGHT);
  96.     for i from 0 upto TEXT_DEPTH - 1 do
  97.         textBitMap.bm_Planes[i] :=
  98.         AllocRaster(TEXT_WIDTH, TEXT_HEIGHT);
  99.         if textBitMap.bm_Planes[i] = nil then
  100.         failing := true;
  101.         fi;
  102.     od;
  103.     
  104.     GraphicsRasInfo.ri_BitMap := &graphicsBitMap;
  105.     GraphicsRasInfo.ri_RxOffset := 0;
  106.     GraphicsRasInfo.ri_RyOffset := GRAPHICS_HEIGHT + 1 - TextTopLine;
  107.     GraphicsRasInfo.ri_Next := nil;
  108.     TextRasInfo.ri_BitMap := &textBitMap;
  109.     TextRasInfo.ri_RxOffset := 0;
  110.     TextRasInfo.ri_RyOffset := TextTopLine;
  111.     TextRasInfo.ri_Next := nil;
  112.     
  113.     InitVPort(&GraphicsViewPort);
  114.     GraphicsViewPort.vp_DWidth := GRAPHICS_WIDTH;
  115.     GraphicsViewPort.vp_DHeight := TextTopLine - 1;
  116.     GraphicsViewPort.vp_DxOffset := 0;
  117.     GraphicsViewPort.vp_DyOffset := 0;
  118.     GraphicsViewPort.vp_RasInfo := &GraphicsRasInfo;
  119.     GraphicsViewPort.vp_ColorMap := GetColorMap(GRAPHICS_COLORS);
  120.     if GraphicsViewPort.vp_ColorMap = nil then
  121.         failing := true;
  122.     fi;
  123.     GraphicsViewPort.vp_Next := &TextViewPort;
  124.     InitVPort(&TextViewPort);
  125.     TextViewPort.vp_Modes := HIRES;
  126.     TextViewPort.vp_DWidth := TEXT_WIDTH;
  127.     TextViewPort.vp_DHeight := TEXT_HEIGHT - TextTopLine;
  128.     TextViewPort.vp_DxOffset := 0;
  129.     TextViewPort.vp_DyOffset := TextTopLine;
  130.     TextViewPort.vp_RasInfo := &TextRasInfo;
  131.     TextViewPort.vp_ColorMap := GetColorMap(TEXT_COLORS);
  132.     if TextViewPort.vp_ColorMap = nil then
  133.         failing := true;
  134.     fi;
  135.  
  136.     InitRastPort(&GraphicsRastPort);
  137.     GraphicsRastPort.rp_BitMap := &graphicsBitMap;
  138.     InitRastPort(&TextRastPort);
  139.     TextRastPort.rp_BitMap := &textBitMap;
  140.     
  141.     if not failing then
  142.         SetAPen(&GraphicsRastPort, 0);
  143.         RectFill(&GraphicsRastPort, 0, 0,
  144.         GRAPHICS_WIDTH - 1, GRAPHICS_HEIGHT - 1);
  145.         SetAPen(&TextRastPort, 0);
  146.         RectFill(&TextRastPort, 0, 0, TEXT_WIDTH - 1, TEXT_HEIGHT - 1);
  147.  
  148.         MakeVPort(&View, &TextViewPort);
  149.         MakeVPort(&View, &GraphicsViewPort);
  150.         MrgCop(&View);
  151.         LoadView(&View);
  152.     
  153.         doit();
  154.     
  155.         LoadView(oldView);
  156.  
  157.         FreeVPortCopLists(&GraphicsViewPort);
  158.         FreeVPortCopLists(&TextViewPort);
  159.         FreeCprList(View.v_LOFCprList);
  160.     fi;
  161.     
  162.     for i from 0 upto GRAPHICS_DEPTH - 1 do
  163.         if graphicsBitMap.bm_Planes[i] ~= nil then
  164.         FreeRaster(graphicsBitMap.bm_Planes[i],
  165.             GRAPHICS_WIDTH, GRAPHICS_HEIGHT);
  166.         fi;
  167.     od;
  168.     for i from 0 upto TEXT_DEPTH - 1 do
  169.         if textBitMap.bm_Planes[i] ~= nil then
  170.         FreeRaster(textBitMap.bm_Planes[i], TEXT_WIDTH, TEXT_HEIGHT);
  171.         fi;
  172.     od;
  173.  
  174.     if GraphicsViewPort.vp_ColorMap ~= nil then
  175.         FreeColorMap(GraphicsViewPort.vp_ColorMap);
  176.     fi;
  177.     if TextViewPort.vp_ColorMap ~= nil then
  178.         FreeColorMap(TextViewPort.vp_ColorMap);
  179.     fi;
  180.     
  181.     CloseGraphicsLibrary();
  182.     fi;
  183. corp;
  184.